package com.yanfan.energy.mapper;


import com.yanfan.energy.domain.Common;
import com.yanfan.energy.domain.EquipmentConsumption;
import com.yanfan.energy.domain.EquipmentConsumptionDto;
import com.yanfan.energy.domain.PurchasingEnergy;
import com.yanfan.energy.domain.statist.DateStatistics;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 设备能耗表(EquipmentConsumption)表数据库访问层
 *
 * @author makejava
 * @since 2022-10-11 18:16:45
 */
@Repository
public interface EquipmentConsumptionDao {

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    EquipmentConsumption queryById(Integer id);

    /**
     * 查询指定行数据
     *
     * @param equipmentConsumption 查询条件
     * @param pageable             分页对象
     * @return 对象列表
     */
    List<EquipmentConsumption> queryAllByLimit(EquipmentConsumption equipmentConsumption, @Param("pageable") Pageable pageable);

    /**
     * 统计总行数
     *
     * @param equipmentConsumption 查询条件
     * @return 总行数
     */
    long count(EquipmentConsumption equipmentConsumption);

    /**
     * 新增数据
     *
     * @param equipmentConsumption 实例对象
     * @return 影响行数
     */
    int insert(EquipmentConsumption equipmentConsumption);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<EquipmentConsumption> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<EquipmentConsumption> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<EquipmentConsumption> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<EquipmentConsumption> entities);

    /**
     * 修改数据
     *
     * @param equipmentConsumption 实例对象
     * @return 影响行数
     */
    int update(EquipmentConsumption equipmentConsumption);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 影响行数
     */
    int deleteById(Integer id);

    /**
     * 根据时间排序查询一条
     *
     * @return
     */
    EquipmentConsumption selectequipmentConsumptionOrderBycreatedDateLimit();

    /**
     * 根据时间排序查询一条关联设备表：find设备编号
     *
     * @return
     */
    EquipmentConsumption selectequipmentConsumptionAndDeviceOrderBycreatedDateLimit();

    /**
     * 查询leftjoin设备,车间(同步)
     *
     * @return
     */
    List<EquipmentConsumption> selectOneyly();

    /**
     * 能源报表（按楼宇，能耗分类）查询
     *
     * @param equipmentId
     * @return java.util.List<com.ruoyi.common.core.domain.entity.Common>
     * @author caijinkang
     * @date 2023/5/18 11:15
     */
    List<Common> selectenquipmentConsumptionBycondition(@Param("equipmentId") Long equipmentId);

//    /**
//     * 设备能耗
//     * @param buildingId
//     * @param workshopId
//     * @param deviceId
//     * @param classifyId
//     * @param deviceName
//     * @param begin
//     * @param end
//     * @return
//     */
//    List<EquipmentConsumption> selectequipmentEnergy(@Param("buildingId")Long buildingId,
//                                                     @Param("workshopId")List workshopId,
//                                                     @Param("deviceId")Long deviceId,
//                                                     @Param("classifyId")Long classifyId,
//                                                     @Param("deviceName")String deviceName,
//                                                     @Param("deviceName")String begin,
//                                                     @Param("end")String end);

    /**
     * 设备id查
     *
     * @param deviceId
     * @return
     */
    List<EquipmentConsumptionDto> selectequipmentEnergyBydeviceId(Long deviceId);

    /**
     * 车间id查设备
     *
     * @param workshopId@return
     */
    List<EquipmentConsumptionDto> selectequipmentEnergyByworkshopId(Long workshopId);

    /**
     * 楼栋id查设备
     *
     * @param buildingId
     */
    List<EquipmentConsumptionDto> selectequipmentEnergyBybuildingId(Long buildingId);

    /**
     * 默认查询所有
     *
     * @return
     */
    List<EquipmentConsumptionDto> selectequipmentEnergy();

    /**
     * 根据时间，设备id删除
     *
     * @param time
     * @param id
     */
    void deleteByCreatdateandEquipment(@Param("time") String time, @Param("id") String id);

    int addPurchase(PurchasingEnergy purchasingEnergy);

    int deletePurchase(Integer id);

    int updatePurchase(PurchasingEnergy purchasingEnergy);

    List<PurchasingEnergy> purchase(@Param("begin") String begin, @Param("end") String end);

    List<DateStatistics> purchaseByRange(@Param("begin") String begin, @Param("end") String end, @Param("buildingId") Integer buildingId, @Param("floorId") Integer floorId, @Param("workshopId") Integer workshopId, @Param("unit") Integer unit, @Param("format") String format);

    List<DateStatistics> purchaseByRangeByNumber(@Param("begin") String begin, @Param("end") String end, @Param("buildingId") Integer buildingId, @Param("floorId") Integer floorId, @Param("workshopId") Integer workshopId, @Param("unit") Integer unit, @Param("format") String format);

    List<DateStatistics> purchaseByMonth(@Param("begin") String begin, @Param("end") String end);

    List<PurchasingEnergy> findAllPurchase(@Param("name") String name, @Param("begin") Date begin, @Param("end") Date end);

    List<PurchasingEnergy> findAllPurchaseList();

    String selectDeptAncestors(Long userId);

    /**
     * 查询某个月采购总额
     *
     * @param begin
     * @param end
     * @return java.util.List<com.ruoyi.common.core.domain.model.DateStatistics>
     * @author caijinkang
     * @date 2023/5/10 11:22
     */
    List<DateStatistics> findLastMonthByPurchase(@Param("begin") String begin, @Param("end") String end);

    /**
     * 查询某个月平均每天的采购金额
     *
     * @param begin
     * @param end
     * @return java.util.List<com.ruoyi.common.core.domain.model.DateStatistics>
     * @author caijinkang
     * @date 2023/5/11 10:24
     */
    List<DateStatistics> findLastDayByPurchase(@Param("begin") String begin, @Param("end") String end);


}

